<script type="text/javascript" src="/js/jshash/md5-min.js"></script>
<script type="text/javascript"> 
    function setCipherId() {
        var countryId = document.getElementById('CountryId');
        var code = document.getElementById('Code');
        var codeType = document.getElementById('CodeType');
        var gender = document.getElementById('Gender');
        var cipherId = document.getElementById('CipherId');
        cipherId.value = hex_md5(countryId.value + code.value + codeType.value + gender.value);
    };
</script>
<script type="text/javascript">
    window.onload = function() {
        var officer = document.getElementById('OfficerUserId');
        var group = document.getElementById('GroupId');
        officer.onchange = function () { 
            updateOpts('GroupId', '/admin/json/get-officer-group-options/id/' + officer.value); 
            updateOpts('CommunityId', '/admin/json/get-officer-community-options/id/' + officer.value);
            return false; 
        };    
        group.onchange = function () { 
            if(group.value === 0) { 
                updateOpts('CommunityId', '/admin/json/get-officer-community-options/id/' + officer.value); 
            } else {
                updateOpts('CommunityId', '/admin/json/get-group-community-options/id/' + group.value, groupOnChangeCallback); 
            }
            return false; 
        };  
    };
    function updateOpts(tg,url,callback)
    {
        dojo.xhrGet({
            url: url,
            handleAs: "json",
            timeout: 5000,
            load: function(response, ioArgs) {                
                var obj = dojo.byId(tg);
                obj.options.length = 0;                
                for (index = 0; index < response.length; ++index) {
                    option = response[index];
                    obj.options.add(new Option(option.oT, option.oV));
                }   
                callback();
                return response;
            },
            error: function(response, ioArgs) {
                //alert('Failed xhrGet');
                return response;
            }
        });
    }
    /* callback functions */
    function groupOnChangeCallback() 
    {
        var community = document.getElementById('CommunityId');
        if(community.options[0].value !== 0) { community.selectedIndex = 0; }
    }
</script>

<?php echo $this->form ?>